﻿using System;
using System.Runtime.Serialization;
using MugenMvvmToolkit.Interfaces;

namespace MugenMvvmToolkit.Models
{
    /// <summary>
    /// Represents the interface which contains information about binding a view to a view model.
    /// </summary>
#if WPF
    [Serializable]
#endif
    [DataContract]
    public class ViewMappingItem : IViewMappingItem
    {
        #region Constructor

        /// <summary>
        ///     Initializes a new instance of the <see cref="ViewMappingItem" /> class.
        /// </summary>
        public ViewMappingItem(Type viewModelType, Type viewType, string name)
        {
            Should.NotBeNull(viewModelType, "viewModelType");
            Should.NotBeNull(viewType, "viewType");
            Should.BeViewModel(viewModelType, "viewModelType");
            Should.BeView(viewType, "viewType");
            ViewModelType = viewModelType;
            ViewType = viewType;
            Name = name;
        }

        #endregion

        #region Implementation of IViewPageMappingItem

        /// <summary>
        ///     Gets the name of mapping.
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        ///     Gets the type of view.
        /// </summary>
        public Type ViewType { get; private set; }

        /// <summary>
        ///     Gets or sets the type of view model.
        /// </summary>
        public Type ViewModelType { get; private set; }

        #endregion

        #region Overrides of Object

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return string.Format("View = {0}, ViewType = {1}, Name = {2}", ViewType, ViewModelType, Name ?? string.Empty);
        }

        #endregion
    }
}